/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.is.city.routemanager.GUI;

import java.awt.Component;
import java.awt.HeadlessException;
import java.awt.ItemSelectable;
import java.awt.event.ActionEvent;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.ResourceBundle;
import java.util.Set;
import javax.swing.AbstractAction;
import javax.swing.ComboBoxModel;
import javax.swing.DefaultComboBoxModel;
import javax.swing.DefaultListModel;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.JPanel;
import javax.swing.ListCellRenderer;
import javax.swing.ListModel;
import javax.swing.event.ListDataListener;
import org.geotools.map.FeatureLayer;
import org.geotools.map.Layer;
import org.geotools.map.MapLayer;
import org.is.city.LayersFilter;
import org.is.city.routemanager.RoutePanel;

/**
 *
 * @author oleg
 */
public class ModuleSettingsFrame extends JFrame {

    private static final ResourceBundle stringRes = ResourceBundle.getBundle("META-INF/Text");
    RoutePanel routePanel;
    JComboBox<MapLayer> comboBox;
    DefaultComboBoxModel<MapLayer> model;

    public ModuleSettingsFrame(final RoutePanel routePanel) {
        this.routePanel = routePanel;
        this.setTitle(stringRes.getString("RoutePanel_Settings_Title"));
        this.setBounds(400, 100, 500, 400);
        JPanel jPanel = new JPanel();
        JLabel label = new JLabel(stringRes.getString("RoutePanel_Settings_Choose_guidance_layer"));
        MapLayer[] layers = routePanel.getPane().getMapContext().getLayers();
        model = new DefaultComboBoxModel<MapLayer>();

        int i = 0;
        for (MapLayer layer : layers) {
            if(LayersFilter.isUnknown(layer)){
                model.addElement(layer);
                //System.out.println(layer.getTitle());
            }
            i++;
        }
        MapLayer guidanceLayer = routePanel.getGuidanceLayer();
        comboBox = new JComboBox<MapLayer>(model);
        
        //по умолчанию должен быть текущий слой маршрутизации
        comboBox.setSelectedItem(guidanceLayer);

        comboBox.setRenderer(new MyListCellRenderer());
        comboBox.setSize(300, 30);
        jPanel.add(label);
        jPanel.add(comboBox);
        comboBox.setLocation(200, 50);

        label.setLocation(0, 0);
        this.add(jPanel);
        comboBox.addItemListener(new ItemListener()  {

            @Override
            public void itemStateChanged(ItemEvent e) {
                if (e.getItem() instanceof MapLayer) {
                    
                    System.out.println("MapLayer");
                    MapLayer mapLayer=(MapLayer)e.getItem();
                    System.out.println("Title: "+mapLayer.getFeatureSource().getName().getLocalPart());
                    routePanel.setGuidanceLayer(mapLayer);
                }
            }
        });
    }
}
